package com.example.yoga.controller;

import com.example.yoga.service.ex.*;
import com.example.yoga.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {

    public static final int OK=2000;

    @ExceptionHandler
    public JsonResult<Void> handleServiceException(ServiceException e){
        JsonResult<Void> jr=new JsonResult<>(e);

        if (e instanceof UserNameDuplicateException) {
            jr.setState(4001);
            //jr.setMessage(e.getMessage());
        } else if (e instanceof UserNotFoundException) {
            jr.setState(4002);
           // jr.setMessage(e.getMessage());
        } else if (e instanceof PasswordNotMatchException) {
            jr.setState(4003);
            //jr.setMessage(e.getMessage());
        }else if (e instanceof ProductNotFoundException) {
            jr.setState(4004);
            //jr.setMessage(e.getMessage());
        } else if (e instanceof InsertException) {
            jr.setState(5001);
            //jr.setMessage(e.getMessage());
        }
        return jr;
    }
}
